<template>
    <div style="padding:6px;">
        <el-card v-show="showSearch" style="margin-bottom:5px;">
            <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px" style="margin-bottom:-20px;">
<!--                <el-form-item label="设备名称" prop="name">-->
<!--                    <el-input v-model="queryParams.code" placeholder="请输入参数编码" clearable size="small"-->
<!--                        @keyup.enter.native="handleQuery" />-->
<!--                </el-form-item>-->
                <el-form-item label="设备编码" prop="name">
                  <el-input v-model="queryParams.deviceCode" placeholder="请输入参数名称" clearable size="small"
                            @keyup.enter.native="handleQuery" />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                    <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                </el-form-item>
            </el-form>
        </el-card>
      <div style="width: 1000px;height: 500px">
        <div id="main">ECharts图表区域1</div>
      </div>
        <el-card style="padding-bottom:100px;">
            <el-table v-loading="loading" :data="parameterList" border>
                <el-table-column label="参数ID" align="center" prop="id" />
                <el-table-column label="设备名称" align="center" prop="deviceName" />
                <el-table-column label="设备编码" align="center" header-align="center" prop="deviceCode" min-width="120" />
<!--                <el-table-column label="设备型号" align="center" prop="deviceModel" />-->
<!--                <el-table-column label="设备规格" align="center" prop="deviceNorm" />-->
<!--                <el-table-column label="设备ip" align="center" prop="gatewayId" />-->
                <el-table-column label="监测时间" align="center" prop="monitorTime" />
                <el-table-column label="参数名称" align="center" prop="parmaterName" />
                <el-table-column label="参数编码" align="center" prop="parmaterCode" />
                <el-table-column label="参数值" align="center" prop="parmaterValue" />
<!--                <el-table-column label="创建时间" align="center" prop="createTime" />-->
<!--                <el-table-column label="工厂id" align="center" prop="productId" />-->
            </el-table>

            <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList" />

        </el-card>
    </div>
</template>

<script>
import {
  listMonitor,
} from "@/api/iot/monitor";
import { getDevice } from '@/api/iot/device';
import * as echarts from 'echarts';

export default {
    name: "Parameter",
    dicts: ["iot_yes_no"],
    data() {
        return {
            // 是否为租户
            isTenant: false,
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 产品分类表格数据
            parameterList: [],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                deviceCode: ""
            },
            // 表单参数
            form: {
              productId: 0
            },
            // 表单校验
            rules: {
                code: [{
                  required: true,
                  message: "参数编码不能为空",
                  trigger: "blur"
                }
                ],
                name: [{
                    required: true,
                    message: "参数名称不能为空",
                    trigger: "blur"
                },
                ],
            }
        };
    },
    created() {
        this.init();
        // 获取设备信息
        this.form.deviceId = this.$route.query && this.$route.query.deviceId;
        if (this.form.deviceId != 0) {
          // this.connectMqtt();
          this.getDevice(this.form.deviceId);
        }
    },
    mounted() {
      this.initEChart1();
    },
  methods: {
        init() {
            if (this.$store.state.user.roles.indexOf("tenant") !== -1) {
                this.isTenant = true
            }
        },
        /**获取设备详情*/
        getDevice(deviceId) {
          getDevice(deviceId).then((response) => {
            this.queryParams.deviceCode = response.data.serialNumber;
            this.getList();
          });
        },
        /** 查询设备参数列表 */
        getList() {
          this.loading = true;
          listMonitor(this.queryParams).then(response => {
            console.log(11111111111111111111,response)
                this.parameterList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
          this.resetForm("queryForm");
          this.handleQuery();
        },
      initEChart1() {
        var chartDom = document.getElementById('main');
        var myChart = echarts.init(chartDom);
        var option;
        option = {
          xAxis: {
            type: 'category',
            data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
          },
          yAxis: {
            type: 'value'
          },
          series: [
            {
              data: [150, 230, 224, 218, 135, 147, 260],
              type: 'line'
            }
          ]
        };
        myChart.setOption(option);
        console.log("mmmmmmmmmmmmmmmm",myChart)
      },
    }
};
</script>
